package com.hotel.order.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    public static final String ORDER_EVENT_EXCHANGE = "order.event.exchange";
    public static final String ORDER_CREATED_QUEUE = "order.created.queue";
    public static final String PAYMENT_EVENT_EXCHANGE = "payment.event.exchange";
    public static final String PAYMENT_SUCCESS_QUEUE = "payment.success.queue";

    @Bean
    public Exchange orderEventExchange() {
        return ExchangeBuilder.topicExchange(ORDER_EVENT_EXCHANGE).durable(true).build();
    }

    @Bean
    public Queue orderCreatedQueue() {
        return QueueBuilder.durable(ORDER_CREATED_QUEUE).build();
    }

    @Bean
    public Binding bindOrderCreated() {
        return BindingBuilder.bind(orderCreatedQueue()).to(orderEventExchange()).with("order.created").noargs();
    }

    @Bean
    public Exchange paymentEventExchange() {
        return ExchangeBuilder.topicExchange(PAYMENT_EVENT_EXCHANGE).durable(true).build();
    }

    @Bean
    public Queue paymentSuccessQueue() {
        return QueueBuilder.durable(PAYMENT_SUCCESS_QUEUE).build();
    }

    @Bean
    public Binding bindPaymentSuccess() {
        return BindingBuilder.bind(paymentSuccessQueue()).to(paymentEventExchange()).with("payment.success").noargs();
    }
}
